import { detail } from "../services";

const initData = {
  query: {
    keyWord: "",
    action: "",
    tenantId: "",
    beginTime: "",
    endTime: "",
  },
};

export default {
  namespace: "log",
  state: {
    ...initData,
  },
  effects: {
    *detail({ payload }, { call }) {
      const { datas = {}, errCode, errMsg, errortext } = yield call(
        detail,
        payload,
      );
      return { errCode, errMsg: errMsg || errortext, datas };
    },
    *updateState({ payload }, { put }) {
      const resp = yield put({
        type: "save",
        payload: {
          query: payload,
        },
      });
      return resp;
    },
  },
  reducers: {
    save: (state, { payload }) => ({
      ...state,
      ...payload,
    }),
    clearData: () => ({ ...initData }),
  },
};
